package com.xj.demo.loadclass;

public class StaticDeadLockMain extends Thread {
    private char flag;
    public StaticDeadLockMain(char flag) {
        this.flag = flag;
        this.setName("Thread" + flag);
    }

    @Override
    public void run() {
        try {
            Class.forName("com.xj.demo.classload.Static" + flag);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("load complete");
    }

    public static void main(String[] args) {
        StaticDeadLockMain load_1 = new StaticDeadLockMain('A');
        StaticDeadLockMain load_2 = new StaticDeadLockMain('B');
        load_1.start();
        load_2.start();
    }
}
class StaticA{
    static {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            Class.forName("com.xj.demo.loadclass.StaticB");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("load StaticA complete");
    }
}
class StaticB{
    static {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            Class.forName("com.xj.demo.loadclass.StaticA");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("load StaticA complete");
    }
}
